<script lang="ts" setup>
import { useSidebar } from '../composables/sidebar.js';
import VPIconAlignLeft from './icons/VPIconAlignLeft.vue';

defineProps<{
    open: boolean;
}>();

defineEmits<{
    (e: 'open-menu'): void;
}>();

const { hasSidebar } = useSidebar();

function scrollToTop() {
    window.scrollTo({ top: 0, left: 0, behavior: 'smooth' });
}
</script>

<template>
    <div v-if="hasSidebar" class="VPLocalNav">
        <button class="menu" :aria-expanded="open" aria-controls="VPSidebarNav" @click="$emit('open-menu')">
            <VPIconAlignLeft class="menu-icon" />
            <!-- <span class="menu-text">Menu</span> -->
        </button>
    </div>
    <a class="top-link" href="#" @click="scrollToTop"><span></span></a>
</template>

<style scoped>
.VPLocalNav {
    position: sticky;
    top: 0;
    left: 0;
    width: 33px;
    z-index: var(--vp-z-index-local-nav);
    display: flex;
    justify-content: space-between;
    align-items: center;
    /* border-bottom: 1px solid var(--vp-c-divider-light); */
    height: var(--vp-nav-height);
    /* background-color: var(--vp-c-bg); */
    transition: border-color 0.5s, background-color 0.5s;
}

@media (min-width: 960px) {
    .VPLocalNav {
        display: none;
    }
}

.menu {
    display: flex;
    align-items: center;
    padding: 12px 0 11px 0;
    line-height: 24px;
    font-size: 12px;
    font-weight: 500;
    color: var(--character-title-text);
    transition: color 0.5s;
}

.menu:hover {
    color: var(--vp-c-text-1);
    transition: color 0.25s;
}

/* @media (min-width: 768px) {
    .menu {
        padding: 0 32px;
    }
} */

.menu-icon {
    margin-right: 8px;
    width: 25px;
    height: 25px;
    fill: currentColor;
}

.top-link {
    display: block;
    padding: 0 10px;
    width:52px;
    height:52px;
    position: fixed;
    border-radius: 50%;
    right: 5%;
    bottom: 240px;
    opacity: 0.8;
    display:flex;
    align-items: center;
    justify-content: center;
    background: rgba(255, 255, 255, 0.8);
    box-shadow: 0px 0px 10px 0px rgba(18, 18, 65, 0.2);
    z-index: var(--vp-z-index-back-to-top);
}
.dark .top-link {
    background: rgba(57,59,71,0.80);
box-shadow: 0px 0px 10px 0px rgba(18,18,65,0.2);
}
.top-link span {
    width: 22px;
    height: 32px;
    display: block;
    background: url('/assets/back-to-top.svg') no-repeat center;
    background-size: contain;
}

.top-link:hover {
    /* color: var(--vp-c-text-1);
    transition: color 0.25s; */
    opacity: 1;
}

/* @media (min-width: 768px) {
    .top-link {
        padding: 12px 32px 11px;
    }
} */
</style>
